using GameConfig.item;
using UnityEngine;
using UnityEngine.UI;

public class ItemTooltip : MonoBehaviour
{
    [SerializeField] private Text nameText;
    [SerializeField] private Text typeText;
    [SerializeField] private Text descriptionText;
    [SerializeField] private Text valueText;
    [SerializeField] private GameObject bottomPart;
    [Header("建造")]
    public GameObject resourcePanel;
    [SerializeField] private Image[] resourceItem;

    public void SetupTooltip(ItemTb itemDetails, SlotType slotType)
    {
        nameText.text = itemDetails.ItemName;

        //typeText.text = GetItemType(itemDetails.);

        descriptionText.text = itemDetails.Desc;

        bottomPart.SetActive(false);

        //if (itemDetails.itemType == ItemType.Seed || itemDetails.itemType == ItemType.Commodity || itemDetails.itemType == ItemType.Furniture)
        //{
        //    bottomPart.SetActive(true);

        //    var price = itemDetails.itemPrice;
        //    if (slotType == SlotType.Bag)
        //    {
        //        price = (int)(price * itemDetails.sellPercentage);
        //    }

        //    valueText.text = price.ToString();
        //}
        //else
        //{
        //    bottomPart.SetActive(false);
        //}
        LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
    }

    private string GetItemType(ItemType itemType)
    {
        return itemType switch
        {
            ItemType.Seed => "种子",
            ItemType.Commodity => "商品",
            ItemType.Furniture => "家具",
            ItemType.BreakTool => "工具",
            ItemType.ChopTool => "工具",
            ItemType.CollectTool => "工具",
            ItemType.HoeTool => "工具",
            ItemType.ReapTool => "工具",
            ItemType.WaterTool => "工具",
            _ => "无"
        };
    }

    //public void SetupResourcePanel(int ID)
    //{
    //    var bluePrintDetails = InventoryManager.Instance.bluePrintData.GetBluePrintDetails(ID);
    //    for (int i = 0; i < resourceItem.Length; i++)
    //    {
    //        if (i < bluePrintDetails.resourceItem.Length)
    //        {
    //            var item = bluePrintDetails.resourceItem[i];
    //            resourceItem[i].gameObject.SetActive(true);
    //            resourceItem[i].sprite = InventoryManager.Instance.GetItemDetails(item.itemID).itemIcon;
    //            resourceItem[i].transform.GetChild(0).GetComponent<Text>().text = item.itemAmount.ToString();
    //        }
    //        else
    //        {
    //            resourceItem[i].gameObject.SetActive(false);
    //        }
    //    }
    //}
}
